package com.game.mine;

import javax.swing.*;
import java.awt.*;

public class MinesweeperGame {
    public static void main(String[] args) {
        JFrame frame = new JFrame("扫雷游戏");
        MinesweeperPanel gamePanel = new MinesweeperPanel(10, 10, 10); // 10x10 的雷区，10 个地雷

        JLabel mineCountLabel = new JLabel("剩余地雷: " + gamePanel.getRemainingMines());
        JPanel panel = new JPanel(new BorderLayout());
        panel.add(mineCountLabel, BorderLayout.NORTH);
        panel.add(gamePanel, BorderLayout.CENTER);

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(panel);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);

        // 更新剩余地雷数
        gamePanel.addMineCountChangeListener(remainingMines -> {
            mineCountLabel.setText("剩余地雷: " + remainingMines);
            if (remainingMines == 0 && !gamePanel.isGameOver()) {
                JOptionPane.showMessageDialog(frame, "过关！");
            }
        });
    }
}